<?php
/*
whmtools - easily find accounts on cpanels servers
Copyright (C) 2006  Matthew Davis <matthew@familycampground.org>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/


include 'header.php';
include 'config.php';

// Check to see if this page is viewed after
// a submit press.  If so, process the new data
if ($submit) {
  $sql = "UPDATE `servers` SET `hostname` = '$shortName', `ip` = '$serverIP', `username` = '$userName',
                               `hash` = '$hash', `network` = '$network', `local_remote` = '$localremote' where `id` = '$id'";
  mysql_query($sql);
  print "<a href=\"manage-servers.php\">Return to Server Mangement</a>";

} else {

// It wasn't a submit but
// the first hit to the page
// display the data to edit
$sql = "SELECT * from servers where id = $id";
$result = mysql_query($sql);

?>

<form action="modify-server.php" method="post">
  <table>

<?
while ($servers = mysql_fetch_assoc($result)) {
  print "\t<input type=hidden name=id value=" . $servers[id] . ">\n";
  print "\t<tr><td>Shortname</td><td><input type=text name=shortName value=" . $servers[hostname] . "></td></tr>\n";
  print "\t<tr><td>IP</td><td><input type=text name=serverIP value=" . $servers[ip] . "></td></tr>\n";
  print "\t<tr><td>Username</td><td><input type=text name=userName value=" . $servers[username] . "></td></tr>\n";
  print "\t<tr><td>Network</td><td><input type=text name=network value=" . $servers[network] . "></td></tr>\n";
  print "\t<tr><td>Local or Remote Query</td>\n";

# determine which radio button should be selected
if ($servers[local_remote] == '0') $local = "CHECKED";
elseif ($servers[local_remote] == '1') $remote = "CHECKED";

  print "\t\t<td><input type=radio name=localremote value=0 $local> Local\n";
  print "\t\t<input type=radio name=localremote value=1 $remote> Remote</td></tr>\n";
  print "\t<tr><td>Hash</td><td><textarea name=hash rows=\"29\" cols=\"40\">" . $servers[hash] . "</textarea></td></tr>\n";
}
?>
    <tr><td colspan="2" align="center"><input type="submit" value="Submit" name="submit" /><input type="reset" value="Reset" /></td></tr>
  </table>
</form>

<?
}
?>
